package com.{{.PackageName}}.convert;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.neusoft.bizcore.web.dto.AbstractConverter;

import {{.PackageName}}.dto.{{.ClassName}}DTO;
import {{.PackageName}}.model.{{.ClassName}};
import {{.PackageName}}.repository.{{.ClassName}}Repository;

@Component
public class {{.ClassName}}Converter extends AbstractConverter<{{.ClassName}}, {{.ClassName}}DTO> {


    @Autowired
    private {{.ClassName}}Repository {{.LowerClassName}}Repository;

    @Override
    public Dictionary toModel(final {{.ClassName}}DTO dto) {
        {{.ClassName}} model;
        if (dto.isNew()) {
            model = new {{.ClassName}}();
        } else {
            model = this.{{.LowerClassName}}Repository.getOne(dto.getId());
        }
        BeanUtils.copyProperties(model,dto);
        return model;
    }

    @Override
    public {{.ClassName}}DTO toDTO(final {{.ClassName}} model, final boolean forListView) {

        final {{.ClassName}}DTO dto = new {{.ClassName}}DTO();
        BeanUtils.copyProperties(dto,model);
        return dto;
    }
}